<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>应用 API | Vue.js</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link href="https://fonts.googleapis.com/css?family=Inter:300,400,500,600|Open+Sans:400,600;display=swap" rel="stylesheet">
    <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link rel="icon" href="/vue3/logo.png">
    <link rel="manifest" href="/vue3/manifest.json">
    <link rel="apple-touch-icon" href="/images/icons/apple-icon-152x152.png">
    <script src="https://player.youku.com/iframeapi"></script>
    <meta name="description" content="Vue.js - The 渐进式 JavaScript 框架">
    <meta name="theme-color" content="#3eaf7c">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="msapplication-TileImage" content="/images/icons/ms-icon-144x144.png">
    <meta name="msapplication-TileColor" content="#000000">
    
    <link rel="preload" href="/vue3/assets/css/0.styles.9bf58a16.css" as="style"><link rel="preload" href="/vue3/assets/js/app.9f011487.js" as="script"><link rel="preload" href="/vue3/assets/js/11.bea13863.js" as="script"><link rel="preload" href="/vue3/assets/js/42.3b63f9c9.js" as="script"><link rel="preload" href="/vue3/assets/js/23.f23a1976.js" as="script"><link rel="prefetch" href="/vue3/assets/js/1.98516ad1.js"><link rel="prefetch" href="/vue3/assets/js/100.94330a5d.js"><link rel="prefetch" href="/vue3/assets/js/101.560a6b49.js"><link rel="prefetch" href="/vue3/assets/js/102.f12c4d91.js"><link rel="prefetch" href="/vue3/assets/js/103.be709996.js"><link rel="prefetch" href="/vue3/assets/js/104.49fdebb1.js"><link rel="prefetch" href="/vue3/assets/js/105.df17d42d.js"><link rel="prefetch" href="/vue3/assets/js/106.fa0a51b7.js"><link rel="prefetch" href="/vue3/assets/js/107.392361bf.js"><link rel="prefetch" href="/vue3/assets/js/108.af6fc4d6.js"><link rel="prefetch" href="/vue3/assets/js/109.18bcf602.js"><link rel="prefetch" href="/vue3/assets/js/110.052b8c4c.js"><link rel="prefetch" href="/vue3/assets/js/111.528533a3.js"><link rel="prefetch" href="/vue3/assets/js/112.28359168.js"><link rel="prefetch" href="/vue3/assets/js/113.190e7aff.js"><link rel="prefetch" href="/vue3/assets/js/114.dddc32bb.js"><link rel="prefetch" href="/vue3/assets/js/115.7924a11d.js"><link rel="prefetch" href="/vue3/assets/js/116.5836841c.js"><link rel="prefetch" href="/vue3/assets/js/117.1e3523ad.js"><link rel="prefetch" href="/vue3/assets/js/118.fda02ea3.js"><link rel="prefetch" href="/vue3/assets/js/119.c56ed999.js"><link rel="prefetch" href="/vue3/assets/js/12.11fdef37.js"><link rel="prefetch" href="/vue3/assets/js/120.14653326.js"><link rel="prefetch" href="/vue3/assets/js/121.5bdc69d1.js"><link rel="prefetch" href="/vue3/assets/js/122.ea246bef.js"><link rel="prefetch" href="/vue3/assets/js/123.1a041b0d.js"><link rel="prefetch" href="/vue3/assets/js/124.4849397b.js"><link rel="prefetch" href="/vue3/assets/js/125.f8a4d9a1.js"><link rel="prefetch" href="/vue3/assets/js/126.e6f8c88f.js"><link rel="prefetch" href="/vue3/assets/js/127.bb0d0c14.js"><link rel="prefetch" href="/vue3/assets/js/128.6fcdf065.js"><link rel="prefetch" href="/vue3/assets/js/129.d37419cf.js"><link rel="prefetch" href="/vue3/assets/js/13.84b5a427.js"><link rel="prefetch" href="/vue3/assets/js/130.2ff76428.js"><link rel="prefetch" href="/vue3/assets/js/131.dbd74031.js"><link rel="prefetch" href="/vue3/assets/js/132.b4ca1a54.js"><link rel="prefetch" href="/vue3/assets/js/133.95a81c57.js"><link rel="prefetch" href="/vue3/assets/js/134.da6a25f1.js"><link rel="prefetch" href="/vue3/assets/js/135.46cd4ce4.js"><link rel="prefetch" href="/vue3/assets/js/136.c908c444.js"><link rel="prefetch" href="/vue3/assets/js/137.838c736d.js"><link rel="prefetch" href="/vue3/assets/js/138.5f56ac41.js"><link rel="prefetch" href="/vue3/assets/js/139.2d3218e7.js"><link rel="prefetch" href="/vue3/assets/js/14.ccde2ff7.js"><link rel="prefetch" href="/vue3/assets/js/140.73a6c08b.js"><link rel="prefetch" href="/vue3/assets/js/141.e6e97fa2.js"><link rel="prefetch" href="/vue3/assets/js/142.78b66660.js"><link rel="prefetch" href="/vue3/assets/js/143.18a5f522.js"><link rel="prefetch" href="/vue3/assets/js/144.007967ab.js"><link rel="prefetch" href="/vue3/assets/js/145.69c6c622.js"><link rel="prefetch" href="/vue3/assets/js/146.5eb14458.js"><link rel="prefetch" href="/vue3/assets/js/147.01b7b88c.js"><link rel="prefetch" href="/vue3/assets/js/148.c4464ffa.js"><link rel="prefetch" href="/vue3/assets/js/149.66883751.js"><link rel="prefetch" href="/vue3/assets/js/15.6957b547.js"><link rel="prefetch" href="/vue3/assets/js/150.03ccd0c3.js"><link rel="prefetch" href="/vue3/assets/js/151.5cb25376.js"><link rel="prefetch" href="/vue3/assets/js/152.51fa843b.js"><link rel="prefetch" href="/vue3/assets/js/153.c280bbfc.js"><link rel="prefetch" href="/vue3/assets/js/154.3c1208bb.js"><link rel="prefetch" href="/vue3/assets/js/155.f2bec114.js"><link rel="prefetch" href="/vue3/assets/js/156.9d563e5f.js"><link rel="prefetch" href="/vue3/assets/js/157.09a62483.js"><link rel="prefetch" href="/vue3/assets/js/158.e8ee954d.js"><link rel="prefetch" href="/vue3/assets/js/159.806c0da5.js"><link rel="prefetch" href="/vue3/assets/js/16.1c3a9fe2.js"><link rel="prefetch" href="/vue3/assets/js/160.70fe7ee3.js"><link rel="prefetch" href="/vue3/assets/js/161.7b67e86f.js"><link rel="prefetch" href="/vue3/assets/js/162.d2cb71f8.js"><link rel="prefetch" href="/vue3/assets/js/163.c2f8c96a.js"><link rel="prefetch" href="/vue3/assets/js/164.c0ce5d22.js"><link rel="prefetch" href="/vue3/assets/js/165.dd31fc10.js"><link rel="prefetch" href="/vue3/assets/js/166.861df1bd.js"><link rel="prefetch" href="/vue3/assets/js/167.8cade3be.js"><link rel="prefetch" href="/vue3/assets/js/168.d384c54a.js"><link rel="prefetch" href="/vue3/assets/js/169.266b17c8.js"><link rel="prefetch" href="/vue3/assets/js/17.13ae2912.js"><link rel="prefetch" href="/vue3/assets/js/170.8da5cca1.js"><link rel="prefetch" href="/vue3/assets/js/171.59233d62.js"><link rel="prefetch" href="/vue3/assets/js/172.e2ff7db9.js"><link rel="prefetch" href="/vue3/assets/js/173.4fae5fdf.js"><link rel="prefetch" href="/vue3/assets/js/174.25d65654.js"><link rel="prefetch" href="/vue3/assets/js/175.0fd8e932.js"><link rel="prefetch" href="/vue3/assets/js/176.afbb20d7.js"><link rel="prefetch" href="/vue3/assets/js/177.3fce4ef4.js"><link rel="prefetch" href="/vue3/assets/js/178.a69eab8f.js"><link rel="prefetch" href="/vue3/assets/js/179.b9c69246.js"><link rel="prefetch" href="/vue3/assets/js/18.2176f64f.js"><link rel="prefetch" href="/vue3/assets/js/180.80eaf61f.js"><link rel="prefetch" href="/vue3/assets/js/181.8c9ea68f.js"><link rel="prefetch" href="/vue3/assets/js/182.363237b2.js"><link rel="prefetch" href="/vue3/assets/js/183.1bcce34d.js"><link rel="prefetch" href="/vue3/assets/js/184.63965c38.js"><link rel="prefetch" href="/vue3/assets/js/185.145d17f7.js"><link rel="prefetch" href="/vue3/assets/js/186.01c28041.js"><link rel="prefetch" href="/vue3/assets/js/187.651fc5e1.js"><link rel="prefetch" href="/vue3/assets/js/188.371a53d8.js"><link rel="prefetch" href="/vue3/assets/js/189.21a8c4f3.js"><link rel="prefetch" href="/vue3/assets/js/19.f35e6099.js"><link rel="prefetch" href="/vue3/assets/js/2.655ed906.js"><link rel="prefetch" href="/vue3/assets/js/20.6a9108db.js"><link rel="prefetch" href="/vue3/assets/js/21.b90deaac.js"><link rel="prefetch" href="/vue3/assets/js/22.2da4161c.js"><link rel="prefetch" href="/vue3/assets/js/24.0f4c4cde.js"><link rel="prefetch" href="/vue3/assets/js/25.3a155505.js"><link rel="prefetch" href="/vue3/assets/js/26.d7a45b3e.js"><link rel="prefetch" href="/vue3/assets/js/27.3c237b85.js"><link rel="prefetch" href="/vue3/assets/js/28.1722182e.js"><link rel="prefetch" href="/vue3/assets/js/29.158159ee.js"><link rel="prefetch" href="/vue3/assets/js/3.9e67029d.js"><link rel="prefetch" href="/vue3/assets/js/30.085c3faf.js"><link rel="prefetch" href="/vue3/assets/js/31.d95eaf7d.js"><link rel="prefetch" href="/vue3/assets/js/32.75be14cd.js"><link rel="prefetch" href="/vue3/assets/js/33.b9adbce6.js"><link rel="prefetch" href="/vue3/assets/js/34.ef96058c.js"><link rel="prefetch" href="/vue3/assets/js/35.f2d110b9.js"><link rel="prefetch" href="/vue3/assets/js/36.11e69166.js"><link rel="prefetch" href="/vue3/assets/js/37.d51d98ce.js"><link rel="prefetch" href="/vue3/assets/js/38.ba303c3e.js"><link rel="prefetch" href="/vue3/assets/js/39.7af701c4.js"><link rel="prefetch" href="/vue3/assets/js/4.2768033f.js"><link rel="prefetch" href="/vue3/assets/js/40.50b39df3.js"><link rel="prefetch" href="/vue3/assets/js/41.377521c6.js"><link rel="prefetch" href="/vue3/assets/js/43.98898a3b.js"><link rel="prefetch" href="/vue3/assets/js/44.29a6e6a2.js"><link rel="prefetch" href="/vue3/assets/js/45.7d0883fe.js"><link rel="prefetch" href="/vue3/assets/js/46.4e93f7dd.js"><link rel="prefetch" href="/vue3/assets/js/47.4c629b92.js"><link rel="prefetch" href="/vue3/assets/js/48.f1bf29a9.js"><link rel="prefetch" href="/vue3/assets/js/49.a49482a4.js"><link rel="prefetch" href="/vue3/assets/js/5.175dbe8f.js"><link rel="prefetch" href="/vue3/assets/js/50.dbad5716.js"><link rel="prefetch" href="/vue3/assets/js/51.76b7354d.js"><link rel="prefetch" href="/vue3/assets/js/52.3a1a9a63.js"><link rel="prefetch" href="/vue3/assets/js/53.be592e24.js"><link rel="prefetch" href="/vue3/assets/js/54.d97c6e79.js"><link rel="prefetch" href="/vue3/assets/js/55.eff64da2.js"><link rel="prefetch" href="/vue3/assets/js/56.e3dc0e44.js"><link rel="prefetch" href="/vue3/assets/js/57.d7b38bdd.js"><link rel="prefetch" href="/vue3/assets/js/58.fdc076c9.js"><link rel="prefetch" href="/vue3/assets/js/59.9f11e0ea.js"><link rel="prefetch" href="/vue3/assets/js/6.c6369861.js"><link rel="prefetch" href="/vue3/assets/js/60.a818862d.js"><link rel="prefetch" href="/vue3/assets/js/61.bb9ab96c.js"><link rel="prefetch" href="/vue3/assets/js/62.116aefff.js"><link rel="prefetch" href="/vue3/assets/js/63.be6c07d0.js"><link rel="prefetch" href="/vue3/assets/js/64.0ad95216.js"><link rel="prefetch" href="/vue3/assets/js/65.f8749c54.js"><link rel="prefetch" href="/vue3/assets/js/66.7680f482.js"><link rel="prefetch" href="/vue3/assets/js/67.6fba4d5a.js"><link rel="prefetch" href="/vue3/assets/js/68.ed63b04b.js"><link rel="prefetch" href="/vue3/assets/js/69.73b3bf13.js"><link rel="prefetch" href="/vue3/assets/js/7.cd1985fe.js"><link rel="prefetch" href="/vue3/assets/js/70.6e7dc295.js"><link rel="prefetch" href="/vue3/assets/js/71.32c17a2a.js"><link rel="prefetch" href="/vue3/assets/js/72.ab8b426d.js"><link rel="prefetch" href="/vue3/assets/js/73.73838f6c.js"><link rel="prefetch" href="/vue3/assets/js/74.c3c5f3e6.js"><link rel="prefetch" href="/vue3/assets/js/75.5f63164c.js"><link rel="prefetch" href="/vue3/assets/js/76.6071fb5c.js"><link rel="prefetch" href="/vue3/assets/js/77.1f274f68.js"><link rel="prefetch" href="/vue3/assets/js/78.16d4c50b.js"><link rel="prefetch" href="/vue3/assets/js/79.fc2b2e03.js"><link rel="prefetch" href="/vue3/assets/js/80.42173ce4.js"><link rel="prefetch" href="/vue3/assets/js/81.51405a99.js"><link rel="prefetch" href="/vue3/assets/js/82.be2d0e4f.js"><link rel="prefetch" href="/vue3/assets/js/83.75b4d2af.js"><link rel="prefetch" href="/vue3/assets/js/84.fbaa5717.js"><link rel="prefetch" href="/vue3/assets/js/85.60063971.js"><link rel="prefetch" href="/vue3/assets/js/86.cf80c75d.js"><link rel="prefetch" href="/vue3/assets/js/87.eca6cea7.js"><link rel="prefetch" href="/vue3/assets/js/88.3967efe4.js"><link rel="prefetch" href="/vue3/assets/js/89.bf83cb8c.js"><link rel="prefetch" href="/vue3/assets/js/90.96996b25.js"><link rel="prefetch" href="/vue3/assets/js/91.31b5ee41.js"><link rel="prefetch" href="/vue3/assets/js/92.d197feb2.js"><link rel="prefetch" href="/vue3/assets/js/93.b471c7fe.js"><link rel="prefetch" href="/vue3/assets/js/94.b4298707.js"><link rel="prefetch" href="/vue3/assets/js/95.2f91d14f.js"><link rel="prefetch" href="/vue3/assets/js/96.18b64251.js"><link rel="prefetch" href="/vue3/assets/js/97.363729fa.js"><link rel="prefetch" href="/vue3/assets/js/98.cb8f0be4.js"><link rel="prefetch" href="/vue3/assets/js/99.f62cf45d.js"><link rel="prefetch" href="/vue3/assets/js/vendors~docsearch.5cf23a03.js"><link rel="prefetch" href="/vue3/assets/js/vendors~search-page.d14326ff.js">
    <link rel="stylesheet" href="/vue3/assets/css/0.styles.9bf58a16.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><!----> <header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/vue3/" class="home-link router-link-active"><img src="/vue3/logo.png" alt="Vue.js" class="logo"> <span class="site-name can-hide">Vue.js</span></a> <span style="font-size:.9rem;color:#2c3e50;margin-left:20px;">非官方文档，查看官方文档请移步<a href="https://v3.cn.vuejs.org/" target="_blank">这里</a></span> <div class="links"><!----> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="文档菜单" class="dropdown-title"><span class="title">文档</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue3/guide/introduction.html" class="nav-link">
  教程
</a></li><li class="dropdown-item"><!----> <a href="/vue3/style-guide/" class="nav-link">
  风格指南
</a></li><li class="dropdown-item"><!----> <a href="/vue3/cookbook/" class="nav-link">
  Cookbook
</a></li><li class="dropdown-item"><!----> <a href="/vue3/examples/markdown.html" class="nav-link">
  示例
</a></li><li class="dropdown-item"><!----> <a href="/vue3/guide/contributing/writing-guide.html" class="nav-link">
  贡献文档
</a></li><li class="dropdown-item"><!----> <a href="/vue3/guide/migration/introduction.html" class="nav-link">
  从 Vue 2 迁移
</a></li></ul></div></div><div class="nav-item"><a href="/vue3/api/" class="nav-link router-link-active">
  API 参考
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="生态系统" class="dropdown-title"><span class="title">生态系统</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          社区
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vue3/community/team/" class="nav-link">
  团队
</a></li><li class="dropdown-subitem"><a href="/vue3/community/partners.html" class="nav-link">
  合作伙伴
</a></li><li class="dropdown-subitem"><a href="/vue3/community/join/" class="nav-link">
  加入
</a></li><li class="dropdown-subitem"><a href="/vue3/community/themes/" class="nav-link">
  主题
</a></li></ul></li><li class="dropdown-item"><h4>
          官方项目
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://next.router.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue Router
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://next.vuex.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vuex
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://cli.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue CLI
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://next.vue-test-utils.vuejs.org/guide/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue Test Utils
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://devtools.vuejs.org" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Devtools
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://news.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Weekly news
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://blog.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Blog
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="支持 Vue" class="dropdown-title"><span class="title">支持 Vue</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue3/support-vuejs/#一次性捐款" class="nav-link">
  一次性捐款
</a></li><li class="dropdown-item"><!----> <a href="/vue3/support-vuejs/#周期性赞助" class="nav-link">
  周期性捐款
</a></li><li class="dropdown-item"><!----> <a href="https://www.smallsticker.com/%E8%B4%B4%E7%BA%B8/vue.html" target="_blank" rel="noopener noreferrer" class="nav-link external">
  贴纸
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://osholic.com/?utm_source=vue&amp;utm_medium=dropdown" target="_blank" rel="noopener noreferrer" class="nav-link external">
  周边
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://vue.threadless.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  T-Shirt 商店
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="多语言" class="dropdown-title"><span class="title">多语言</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://v3.vuejs.org/" target="_blank" class="nav-link external">
  English
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://v3.ko.vuejs.org/" target="_blank" class="nav-link external">
  한국어
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://v3.ja.vuejs.org/" target="_blank" class="nav-link external">
  日本語
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://v3.ru.vuejs.org/ru/" target="_blank" class="nav-link external">
  Русский
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="/vue3/guide/contributing/translations.html#community-translations" class="nav-link">
  更多翻译
</a></li></ul></div></div> <a href="https://github.com/vuejs/docs-next-zh-cn" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav> <div id="docsearch"></div></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="文档菜单" class="dropdown-title"><span class="title">文档</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue3/guide/introduction.html" class="nav-link">
  教程
</a></li><li class="dropdown-item"><!----> <a href="/vue3/style-guide/" class="nav-link">
  风格指南
</a></li><li class="dropdown-item"><!----> <a href="/vue3/cookbook/" class="nav-link">
  Cookbook
</a></li><li class="dropdown-item"><!----> <a href="/vue3/examples/markdown.html" class="nav-link">
  示例
</a></li><li class="dropdown-item"><!----> <a href="/vue3/guide/contributing/writing-guide.html" class="nav-link">
  贡献文档
</a></li><li class="dropdown-item"><!----> <a href="/vue3/guide/migration/introduction.html" class="nav-link">
  从 Vue 2 迁移
</a></li></ul></div></div><div class="nav-item"><a href="/vue3/api/" class="nav-link router-link-active">
  API 参考
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="生态系统" class="dropdown-title"><span class="title">生态系统</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          社区
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vue3/community/team/" class="nav-link">
  团队
</a></li><li class="dropdown-subitem"><a href="/vue3/community/partners.html" class="nav-link">
  合作伙伴
</a></li><li class="dropdown-subitem"><a href="/vue3/community/join/" class="nav-link">
  加入
</a></li><li class="dropdown-subitem"><a href="/vue3/community/themes/" class="nav-link">
  主题
</a></li></ul></li><li class="dropdown-item"><h4>
          官方项目
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://next.router.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue Router
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://next.vuex.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vuex
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://cli.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue CLI
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://next.vue-test-utils.vuejs.org/guide/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue Test Utils
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://devtools.vuejs.org" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Devtools
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://news.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Weekly news
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://blog.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Blog
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="支持 Vue" class="dropdown-title"><span class="title">支持 Vue</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue3/support-vuejs/#一次性捐款" class="nav-link">
  一次性捐款
</a></li><li class="dropdown-item"><!----> <a href="/vue3/support-vuejs/#周期性赞助" class="nav-link">
  周期性捐款
</a></li><li class="dropdown-item"><!----> <a href="https://www.smallsticker.com/%E8%B4%B4%E7%BA%B8/vue.html" target="_blank" rel="noopener noreferrer" class="nav-link external">
  贴纸
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://osholic.com/?utm_source=vue&amp;utm_medium=dropdown" target="_blank" rel="noopener noreferrer" class="nav-link external">
  周边
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://vue.threadless.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  T-Shirt 商店
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="多语言" class="dropdown-title"><span class="title">多语言</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://v3.vuejs.org/" target="_blank" class="nav-link external">
  English
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://v3.ko.vuejs.org/" target="_blank" class="nav-link external">
  한국어
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://v3.ja.vuejs.org/" target="_blank" class="nav-link external">
  日本語
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://v3.ru.vuejs.org/ru/" target="_blank" class="nav-link external">
  Русский
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="/vue3/guide/contributing/translations.html#community-translations" class="nav-link">
  更多翻译
</a></li></ul></div></div> <a href="https://github.com/vuejs/docs-next-zh-cn" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><a href="/vue3/api/application-config.html" class="sidebar-link">应用配置</a></li><li><a href="/vue3/api/application-api.html" aria-current="page" class="active sidebar-link">应用 API</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/vue3/api/application-api.html#component" class="sidebar-link">component</a></li><li class="sidebar-sub-header"><a href="/vue3/api/application-api.html#config" class="sidebar-link">config</a></li><li class="sidebar-sub-header"><a href="/vue3/api/application-api.html#directive" class="sidebar-link">directive</a></li><li class="sidebar-sub-header"><a href="/vue3/api/application-api.html#mixin" class="sidebar-link">mixin</a></li><li class="sidebar-sub-header"><a href="/vue3/api/application-api.html#mount" class="sidebar-link">mount</a></li><li class="sidebar-sub-header"><a href="/vue3/api/application-api.html#provide" class="sidebar-link">provide</a></li><li class="sidebar-sub-header"><a href="/vue3/api/application-api.html#unmount" class="sidebar-link">unmount</a></li><li class="sidebar-sub-header"><a href="/vue3/api/application-api.html#use" class="sidebar-link">use</a></li><li class="sidebar-sub-header"><a href="/vue3/api/application-api.html#version" class="sidebar-link">version</a></li></ul></li><li><a href="/vue3/api/global-api.html" class="sidebar-link">全局 API</a></li><li><section class="sidebar-group depth-0"><a href="/vue3/api/options-api" class="sidebar-heading clickable"><span>选项</span> <!----></a> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue3/api/options-data.html" class="sidebar-link">Data</a></li><li><a href="/vue3/api/options-dom.html" class="sidebar-link">DOM</a></li><li><a href="/vue3/api/options-lifecycle-hooks.html" class="sidebar-link">生命周期钩子</a></li><li><a href="/vue3/api/options-assets.html" class="sidebar-link">选项/资源</a></li><li><a href="/vue3/api/options-composition.html" class="sidebar-link">组合</a></li><li><a href="/vue3/api/options-misc.html" class="sidebar-link">杂项</a></li></ul></section></li><li><a href="/vue3/api/instance-properties.html" class="sidebar-link">实例 property</a></li><li><a href="/vue3/api/instance-methods.html" class="sidebar-link">实例方法</a></li><li><a href="/vue3/api/directives.html" class="sidebar-link">指令</a></li><li><a href="/vue3/api/special-attributes.html" class="sidebar-link">特殊 attribute</a></li><li><a href="/vue3/api/built-in-components.html" class="sidebar-link">内置组件</a></li><li><section class="sidebar-group depth-0"><a href="/vue3/api/reactivity-api" class="sidebar-heading clickable"><span>响应性 API</span> <!----></a> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue3/api/basic-reactivity.html" class="sidebar-link">响应性基础 API</a></li><li><a href="/vue3/api/refs-api.html" class="sidebar-link">Refs</a></li><li><a href="/vue3/api/computed-watch-api.html" class="sidebar-link">Computed 与 watch</a></li><li><a href="/vue3/api/effect-scope.html" class="sidebar-link">Effect 作用域 API</a></li></ul></section></li><li><a href="/vue3/api/composition-api.html" class="sidebar-link">组合式 API</a></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>单文件组件</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue3/api/sfc-spec.html" class="sidebar-link">规范</a></li><li><a href="/vue3/api/sfc-tooling.html" class="sidebar-link">工具</a></li><li><a href="/vue3/api/sfc-script-setup.html" class="sidebar-link">&lt;script setup&gt;</a></li><li><a href="/vue3/api/sfc-style.html" class="sidebar-link">&lt;style&gt; 特性</a></li></ul></section></li></ul> </aside> <main class="page"><div class="carbon-ads"></div>  <div class="theme-default-content content__default"><h1 id="应用-api"><a href="#应用-api" class="header-anchor">#</a> 应用 API</h1> <p>在 Vue 3 中，改变全局 Vue 行为的 API 现在被移动到了由新的 <code>createApp</code> 方法所创建的应用实例上。此外，现在它们的影响仅限于该特定应用实例：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> createApp <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>

<span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>调用 <code>createApp</code> 返回一个应用实例。该实例提供了一个应用上下文。应用实例挂载的整个组件树共享相同的上下文，该上下文提供了之前在 Vue 2.x 中“全局”的配置。</p> <p>另外，由于 <code>createApp</code> 方法返回应用实例本身，因此可以在其后链式调用其它方法，这些方法可以在以下部分中找到。</p> <h2 id="component"><a href="#component" class="header-anchor">#</a> component</h2> <ul><li><p><strong>参数：</strong></p> <ul><li><code>{string} name</code></li> <li><code>{Function | Object} [definition]</code></li></ul></li> <li><p><strong>返回值：</strong></p> <ul><li>如果传入 <code>definition</code> 参数，返回应用实例。</li> <li>如果不传入 <code>definition</code> 参数，返回组件定义。</li></ul></li> <li><p><strong>用法：</strong></p> <p>注册或检索全局组件。注册还会使用给定的 <code>name</code> 参数自动设置组件的 <code>name</code>。</p></li> <li><p><strong>示例：</strong></p></li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> createApp <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>

<span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token comment">// 注册一个名为my-component的组件</span>
app<span class="token punctuation">.</span><span class="token function">component</span><span class="token punctuation">(</span><span class="token string">'my-component'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
  <span class="token comment">/* ... */</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token comment">// 检索注册的组件(始终返回构造函数)</span>
<span class="token keyword">const</span> MyComponent <span class="token operator">=</span> app<span class="token punctuation">.</span><span class="token function">component</span><span class="token punctuation">(</span><span class="token string">'my-component'</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><ul><li><strong>参考：</strong><a href="/vue3/guide/component-basics.html">组件基础</a></li></ul> <h2 id="config"><a href="#config" class="header-anchor">#</a> config</h2> <ul><li><strong>用法：</strong></li></ul> <p>包含应用配置的对象。</p> <ul><li><strong>示例：</strong></li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> createApp <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>
<span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>

app<span class="token punctuation">.</span>config <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token operator">...</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><ul><li><strong>参考：</strong><a href="/vue3/api/application-config.html">应用配置</a></li></ul> <h2 id="directive"><a href="#directive" class="header-anchor">#</a> directive</h2> <ul><li><p><strong>参数：</strong></p> <ul><li><code>{string} name</code></li> <li><code>{Function | Object} [definition]</code></li></ul></li> <li><p><strong>返回值：</strong></p> <ul><li>如果传入 <code>definition</code> 参数，返回应用实例。</li> <li>如果不传入 <code>definition</code> 参数，返回指令定义。</li></ul></li> <li><p><strong>用法：</strong></p> <p>注册或检索全局指令。</p></li> <li><p><strong>示例：</strong></p></li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> createApp <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>
<span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token comment">// 注册</span>
app<span class="token punctuation">.</span><span class="token function">directive</span><span class="token punctuation">(</span><span class="token string">'my-directive'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
  <span class="token comment">// 指令是具有一组生命周期的钩子：</span>
  <span class="token comment">// 在绑定元素的 attribute 或事件监听器被应用之前调用</span>
  <span class="token function">created</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token comment">// 在绑定元素的父组件挂载之前调用</span>
  <span class="token function">beforeMount</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token comment">// 绑定元素的父组件被挂载时调用</span>
  <span class="token function">mounted</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token comment">// 在包含组件的 VNode 更新之前调用</span>
  <span class="token function">beforeUpdate</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token comment">// 在包含组件的 VNode 及其子组件的 VNode 更新之后调用</span>
  <span class="token function">updated</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token comment">// 在绑定元素的父组件卸载之前调用</span>
  <span class="token function">beforeUnmount</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token comment">// 卸载绑定元素的父组件时调用</span>
  <span class="token function">unmounted</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token comment">// 注册 (功能指令)</span>
app<span class="token punctuation">.</span><span class="token function">directive</span><span class="token punctuation">(</span><span class="token string">'my-directive'</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
  <span class="token comment">// 这将被作为 `mounted` 和 `updated` 调用</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token comment">// getter, 如果已注册，则返回指令定义</span>
<span class="token keyword">const</span> myDirective <span class="token operator">=</span> app<span class="token punctuation">.</span><span class="token function">directive</span><span class="token punctuation">(</span><span class="token string">'my-directive'</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br></div></div><p>指令钩子传递了这些参数：</p> <h4 id="el"><a href="#el" class="header-anchor">#</a> el</h4> <p>指令绑定到的元素。这可用于直接操作 DOM。</p> <h4 id="binding"><a href="#binding" class="header-anchor">#</a> binding</h4> <p>包含以下 property 的对象。</p> <ul><li><code>instance</code>：使用指令的组件实例。</li> <li><code>value</code>：传递给指令的值。例如，在 <code>v-my-directive=&quot;1 + 1&quot;</code> 中，该值为 <code>2</code>。</li> <li><code>oldValue</code>：先前的值，仅在 <code>beforeUpdate</code> 和 <code>updated</code> 中可用。值是否已更改都可用。</li> <li><code>arg</code>：参数传递给指令 (如果有)。例如在 <code>v-my-directive:foo</code> 中，arg 为 <code>&quot;foo&quot;</code>。</li> <li><code>modifiers</code>：包含修饰符 (如果有) 的对象。例如在 <code>v-my-directive.foo.bar</code> 中，修饰符对象为 <code>{foo: true，bar: true}</code>。</li> <li><code>dir</code>：一个对象，在注册指令时作为参数传递。例如，在以下指令中</li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code>app<span class="token punctuation">.</span><span class="token function">directive</span><span class="token punctuation">(</span><span class="token string">'focus'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
  <span class="token function">mounted</span><span class="token punctuation">(</span><span class="token parameter">el</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    el<span class="token punctuation">.</span><span class="token function">focus</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><code>dir</code> 将会是以下对象：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token punctuation">{</span>
  <span class="token function">mounted</span><span class="token punctuation">(</span><span class="token parameter">el</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    el<span class="token punctuation">.</span><span class="token function">focus</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h4 id="vnode"><a href="#vnode" class="header-anchor">#</a> vnode</h4> <p>上面作为 el 参数收到的真实 DOM 元素的蓝图。</p> <h4 id="prevnode"><a href="#prevnode" class="header-anchor">#</a> prevNode</h4> <p>上一个虚拟节点，仅在 <code>beforeUpdate</code> 和 <code>updated</code> 钩子中可用。</p> <div class="custom-block tip"><p class="custom-block-title">Note</p> <p>除了 <code>el</code> 之外，你应该将这些参数视为只读，并且永远不要修改它们。如果你需要跨钩子共享信息，建议通过元素的<a href="https://developer.mozilla.org/zh-CN/docs/Web/API/HTMLElement/dataset" target="_blank" rel="noopener noreferrer">自定义数据属性集<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>进行共享。</p></div> <ul><li><strong>参考：</strong><a href="/vue3/guide/custom-directive.html">自定义指令</a></li></ul> <h2 id="mixin"><a href="#mixin" class="header-anchor">#</a> mixin</h2> <ul><li><p><strong>参数：</strong></p> <ul><li><code>{Object} mixin</code></li></ul></li> <li><p><strong>返回值：</strong></p> <ul><li>应用实例</li></ul></li> <li><p><strong>用法：</strong></p> <p>将一个 mixin 应用在整个应用范围内。一旦注册，它们就可以在当前的应用中任何组件模板内使用它。插件作者可以使用此方法将自定义行为注入组件。<strong>不建议在应用代码中使用</strong>。</p></li> <li><p><strong>参考：</strong><a href="/vue3/guide/mixins.html#全局-mixin">全局 mixin</a></p></li></ul> <h2 id="mount"><a href="#mount" class="header-anchor">#</a> mount</h2> <ul><li><p><strong>参数：</strong></p> <ul><li><code>{Element | string} rootContainer</code></li> <li><code>{boolean} isHydrate</code></li></ul></li> <li><p><strong>返回值：</strong></p> <ul><li>根组件实例</li></ul></li> <li><p><strong>用法：</strong></p> <p>所提供 DOM 元素的 <code>innerHTML</code> 将被替换为应用根组件的模板渲染结果。</p></li> <li><p><strong>示例：</strong></p></li></ul> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>my-app<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> createApp <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>

<span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token comment">// 做一些必要的准备</span>
app<span class="token punctuation">.</span><span class="token function">mount</span><span class="token punctuation">(</span><span class="token string">'#my-app'</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><ul><li><strong>参考：</strong> <ul><li><a href="/vue3/guide/instance.html#生命周期图示">生命周期图示</a></li></ul></li></ul> <h2 id="provide"><a href="#provide" class="header-anchor">#</a> provide</h2> <ul><li><p><strong>参数：</strong></p> <ul><li><code>{string | Symbol} key</code></li> <li><code>value</code></li></ul></li> <li><p><strong>返回值：</strong></p> <ul><li>应用实例</li></ul></li> <li><p><strong>用法：</strong></p> <p>设置一个可以被注入到应用范围内所有组件中的值。组件应该使用 <code>inject</code> 来接收 provide 的值。</p> <p>从 <code>provide</code>/<code>inject</code> 的角度来看，可以将应用程序视为根级别的祖先，而根组件是其唯一的子级。</p> <p>该方法不应该与 <a href="/vue3/api/options-composition.html#provide-inject">provide 组件选项</a>或组合式 API 中的 <a href="/vue3/api/composition-api.html#provide-inject">provide 方法</a>混淆。虽然它们也是相同的 <code>provide</code>/<code>inject</code> 机制的一部分，但是是用来配置组件 provide 的值而不是应用 provide 的值。</p> <p>通过应用提供值在写插件时尤其有用，因为插件一般不能使用组件提供值。这是使用 <a href="/vue3/api/application-config.html#globalproperties">globalProperties</a> 的替代选择。</p> <div class="custom-block tip"><p class="custom-block-title">Note</p> <p><code>provide</code> 和 <code>inject</code> 绑定不是响应式的。这是有意为之。不过，如果你向下传递一个响应式对象，这个对象上的 property 会保持响应式。</p></div></li> <li><p><strong>示例：</strong></p> <p>向根组件中注入一个 property，值由应用提供。</p></li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> createApp <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>

<span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  inject<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">'user'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
  template<span class="token operator">:</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string"><span class="language-html">
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
      <span class="token interpolation"><span class="token punctuation">{{</span><span class="token inline-js language-js"> user </span><span class="token punctuation">}}</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
  </span></span><span class="token template-punctuation string">`</span></span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>

app<span class="token punctuation">.</span><span class="token function">provide</span><span class="token punctuation">(</span><span class="token string">'user'</span><span class="token punctuation">,</span> <span class="token string">'administrator'</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><ul><li><strong>参考：</strong> <ul><li><a href="/vue3/guide/component-provide-inject.html">Provide / Inject</a></li></ul></li></ul> <h2 id="unmount"><a href="#unmount" class="header-anchor">#</a> unmount</h2> <ul><li><p><strong>用法：</strong></p> <p>卸载应用实例的根组件。</p></li> <li><p><strong>示例：</strong></p></li></ul> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>my-app<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> createApp <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>

<span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token comment">// 做一些必要的准备</span>
app<span class="token punctuation">.</span><span class="token function">mount</span><span class="token punctuation">(</span><span class="token string">'#my-app'</span><span class="token punctuation">)</span>

<span class="token comment">// 挂载5秒后，应用将被卸载</span>
<span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> app<span class="token punctuation">.</span><span class="token function">unmount</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">5000</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="use"><a href="#use" class="header-anchor">#</a> use</h2> <ul><li><p><strong>参数：</strong></p> <ul><li><code>{Object | Function} plugin</code></li> <li><code>...options (可选)</code></li></ul></li> <li><p><strong>返回值：</strong></p> <ul><li>应用实例</li></ul></li> <li><p><strong>用法：</strong></p> <p>安装 Vue.js 插件。如果插件是一个对象，它必须暴露一个 <code>install</code> 方法。如果它本身是一个函数，它将被视为安装方法。</p> <p>该安装方法将以应用实例作为第一个参数被调用。传给 <code>use</code> 的其他 <code>options</code> 参数将作为后续参数传入该安装方法。</p> <p>当在同一个插件上多次调用此方法时，该插件将仅安装一次。</p></li> <li><p><strong>示例：</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> createApp <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>
<span class="token keyword">import</span> MyPlugin <span class="token keyword">from</span> <span class="token string">'./plugins/MyPlugin'</span>

<span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>

app<span class="token punctuation">.</span><span class="token function">use</span><span class="token punctuation">(</span>MyPlugin<span class="token punctuation">)</span>
app<span class="token punctuation">.</span><span class="token function">mount</span><span class="token punctuation">(</span><span class="token string">'#app'</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div></li> <li><p><strong>参考：</strong><a href="/vue3/guide/plugins.html">插件</a></p></li></ul> <h2 id="version"><a href="#version" class="header-anchor">#</a> version</h2> <ul><li><p><strong>用法：</strong></p> <p>以字符串形式提供已安装的 Vue 的版本号。这对于基于不同版本使用不同策略的社区<a href="/vue3/guide/plugins.html">插件</a>来说特别有用。</p></li> <li><p><strong>示例：</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  <span class="token function">install</span><span class="token punctuation">(</span><span class="token parameter">app</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> version <span class="token operator">=</span> <span class="token function">Number</span><span class="token punctuation">(</span>app<span class="token punctuation">.</span>version<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">'.'</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>version <span class="token operator">&lt;</span> <span class="token number">3</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'This plugin requires Vue 3'</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    <span class="token comment">// ...</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div></li> <li><p><strong>参考：</strong><a href="/vue3/api/global-api.html#version">全局 API - version</a></p></li></ul></div> <footer class="page-edit" data-v-007274aa><div class="container" data-v-007274aa><p data-v-007274aa><span class="edit-link" data-v-007274aa>
         发现了错误或者想要为文档做贡献？
          <a href="https://github.com/vuejs/docs-next-zh-cn/edit/master/src/api/application-api.md" target="_blank" rel="noopener noreferrer" data-v-007274aa>
            在 GitHub 上编辑此页
            <span data-v-007274aa><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></span> <!----></p></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/vue3/api/application-config.html" class="prev">应用配置</a></span> <span class="next"><a href="/vue3/api/global-api.html">全局 API</a>
      →
    </span></p></div> <div class="bsa-cpc-wrapper"><div class="bsa-cpc"></div></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/vue3/assets/js/app.9f011487.js" defer></script><script src="/vue3/assets/js/11.bea13863.js" defer></script><script src="/vue3/assets/js/42.3b63f9c9.js" defer></script><script src="/vue3/assets/js/23.f23a1976.js" defer></script>
  </body>
</html>
